package com.flyoil.petromp.mvp_m.CourseDetailModel;

import com.flyoil.petromp.Constant.ConstantNetworkCode;
import com.flyoil.petromp.apiservice.OnObserverRetrofitResetCallBack;
import com.flyoil.petromp.base.BaseEntity;
import com.flyoil.petromp.entity.entity_course_detail.ServiceDemandDetailEntity;
import com.flyoil.petromp.entity.entity_course_detail.ServiceOrderDetailEntity;
import com.flyoil.petromp.entity.entity_order.MapListEntity;
import com.flyoil.petromp.base.BaseModel;
import com.flyoil.petromp.mvp_p.Listener.OnPresenterListener;
import com.flyoil.petromp.mvp_p.Listener.OrderGoodsMessageListener;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by songzhiyin on 2017/11/1.
 * 采购计划明细详情界面数据处理类
 */

public class ServiceOrderDetailModel implements BaseModel {

    @Override
    public void loadNetworkData(Map<String, Object> map, final OnPresenterListener onPresenterListener) {
        httpModel.getCourseServiceOrderDetail(map, new OnObserverRetrofitResetCallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity model) {
                super.onSuccess(model);
                ServiceOrderDetailEntity serviceOrderDetailEntity = null;
                if (model instanceof ServiceOrderDetailEntity) {
                    serviceOrderDetailEntity = (ServiceOrderDetailEntity) model;
                }
                if (serviceOrderDetailEntity != null && serviceOrderDetailEntity.getData() != null && model.getCode() == ConstantNetworkCode.SuccedCode) {
                    ServiceOrderDetailEntity.DataBean dataBean = serviceOrderDetailEntity.getData();
                    OrderGoodsMessageListener listener = (OrderGoodsMessageListener) onPresenterListener;
                    List<MapListEntity> mapListEntities = new ArrayList<>();
                    mapListEntities.add(new MapListEntity("服务内容", dataBean.getServiceContent()));
                    mapListEntities.add(new MapListEntity("执行标准/规范", dataBean.getSpecification()));
                    mapListEntities.add(new MapListEntity("计费金额", dataBean.getPrice()));
                    listener.upDataTextsView(mapListEntities);

                    listener.upDataRemarkView(new MapListEntity("备注", dataBean.getRemark()));
                } else {
                    onPresenterListener.onsucced(null);
                }
            }

            @Override
            public void onFailure(String msg) {
                onPresenterListener.onsucced(null);
//                OrderGoodsMessageListener listener = (OrderGoodsMessageListener) onPresenterListener;
//                List<MapListEntity> mapListEntities = new ArrayList<>();
//                mapListEntities.add(new MapListEntity("服务内容", "摄像机维护"));
//                mapListEntities.add(new MapListEntity("执行标准/规范", "De5522"));
//                mapListEntities.add(new MapListEntity("计费金额", "150元"));
//                listener.upDataTextsView(mapListEntities);
//
//                listener.upDataRemarkView(new MapListEntity("备注", "这是服务备注"));
            }
        });


    }
}
